package com.chen.controller;

import com.chen.anno.Log;
import com.chen.pojo.PageResult;
import com.chen.pojo.Result;
import com.chen.pojo.Student;
import com.chen.service.StudentService;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page(String name,Integer degree,Integer clazzId,Integer page,Integer pageSize) {
        log.info("分页查询，参数：{},{},{},{},{}",name,degree,clazzId,page,pageSize);
        PageResult<Student> dataList=studentService.page(name,degree,clazzId,page,pageSize);
        return Result.success(dataList);
    }
    @Log
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable  List<Integer> ids){
        log.info("批量删除员工:+{}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 添加学生
     * @param student
     * @return
     */
    @Log
    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("添加学生:+{}", student);
        studentService.add(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据id查询员工信息:+{}", id);
        Student student=studentService.getInfo(id);
        return Result.success(student);
    }
    @Log
    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("修改员工信息:+{}", student);
        studentService.update(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result updatescore(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("学员{}违纪扣分:+{}", id,score);
        studentService.updatescore(id,score);
        return Result.success();
    }
}
